//
//  YLMoreIntergralViewModel.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/19.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLMoreIntergralViewModel.h"
#import "WHNetworkTool.h"
#import "YLAccountTool.h"
#import "WHProgressHUD.h"
#import <YYModel.h>
#import "YLMoreIntergralGroup.h"
@implementation YLMoreIntergralViewModel

//- (NSArray<YLMoreIntergralGroup *> *)groups
//{
//    if (!_groups) {
//        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:2];
//
//        {
//            YLMoreIntergralGroup *group = [[YLMoreIntergralGroup alloc] init];
//            group.title = @"积分获取途径";
//            group.iconName = @"getWhere";
//            group.models = @[[YLMoreIntergralModel modelWithContent:@"注册奖励积分"],
//                             [YLMoreIntergralModel modelWithContent:@"签到奖励积分"],
//                             [YLMoreIntergralModel modelWithContent:@"邀请好友奖励积分"],
//                             [YLMoreIntergralModel modelWithContent:@"购买产品奖励积分"],
//                             [YLMoreIntergralModel modelWithContent:@"续投奖励积分"]];
//            [arr addObject:group];
//        }
//
//        {
//            YLMoreIntergralGroup *group = [[YLMoreIntergralGroup alloc] init];
//            group.title = @"积分获取方式";
//            group.iconName = @"getHow";
//            group.models = @[[YLMoreIntergralModel modelWithContent:@"成功注册银来金融即可获得20积分"],
//                             [YLMoreIntergralModel modelWithContent:@"每日签到获得5积分"],
//                             [YLMoreIntergralModel modelWithContent:@"每连续签到7天额外20积分"],
//                             [YLMoreIntergralModel modelWithContent:@"邀请还有获得50积分"],
//                             [YLMoreIntergralModel modelWithContent:@"购买产品年化金额每一万获得200积分"],
//                             [YLMoreIntergralModel modelWithContent:@"续投产品年化金额每一万获得100积分"]];
//            [arr addObject:group];
//
//        }
//
//        _groups = arr;
//    }
//    return _groups;
//}

- (RACCommand *)requestCommand
{
    if (!_requestCommand) {
        __weak typeof(self) weakSelf = self;
        _requestCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                
                NSString *url = [NSString stringWithFormat:@"%@Point/PGetPointWay", YLURL];
                [[WHNetworkTool shareInstance] sendPostWithUrl:url header:[YLAccountTool header] params:nil success:^(id responseObject) {
                    
                    if ([responseObject[@"httpCode"] integerValue] == 200) {
                        YLMoreIntergralGroups *groups = [YLMoreIntergralGroups yy_modelWithDictionary:responseObject];
                        if (groups.httpResult.count > 0) {
                            YLMoreIntergralGroup *firstGroup = groups.httpResult.firstObject;
                            firstGroup.iconName = @"getWhere";
                            YLMoreIntergralGroup *lastGroup = groups.httpResult.lastObject;
                            lastGroup.iconName = @"getHow";
                        }
                        
                        weakSelf.groups = groups;
                        [subscriber sendNext:nil];
                        
                    } else {
                        [WHProgressHUD showError:responseObject[@"message"]];
                    }
                    [subscriber sendCompleted];
                } fail:^(NSError *error) {
                    [subscriber sendCompleted];
                }];
                
                return nil;
            }];
        }];
    }
    return _requestCommand;
}

@end
